package com.swak.consistency.tcc.context;

import lombok.Getter;
import lombok.RequiredArgsConstructor;

/**
 * 事务阶段
 * 
 * @author DELL
 */
@RequiredArgsConstructor
@Getter
public enum Phase {

	/**
	 * READY准备阶段
	 */
	READY(0, "READY准备阶段"),

	/**
	 * TCC try阶段
	 */
	TRYED(1, "try阶段"),

	/**
	 * TCC confirm阶段
	 */
	CONFIRMING(2, "confirm阶段"),

	/**
	 * TCC cancel阶段
	 */
	CANCELING(3, "cancel阶段");

	private final int code;
	private final String desc;

	public static Phase valueOf(int code) {
		Phase[] phases = Phase.values();
		for (Phase phase : phases) {
			if (phase.getCode() == code) {
				return phase;
			}
		}
		return null;
	}
}
